package com.itfreer.print.base.itextpdf.textbefore;

import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;
import com.itfreer.print.base.itextpdf.ITextBefore;

/**
 * 定义页面大小设置信息
 */
public class PageSizeTextBefore implements ITextBefore {
	
	private Rectangle pageSize;
	private float marginLeft;
	private float marginRight;
	private float marginTop;
	private float marginBottom;
	
	/**
	 * 默认为A4
	 */
	public PageSizeTextBefore(){
		this(PageSize.A4, 36, 36, 36, 36);
	}
	
	public PageSizeTextBefore(Rectangle pageSize){
		this(pageSize, 36, 36, 36, 36);
	}
	
	public PageSizeTextBefore(Rectangle pageSize, float marginLeft, float marginRight,
			float marginTop, float marginBottom){
		this.pageSize = pageSize;
		this.marginLeft = marginLeft;
		this.marginRight = marginRight;
		this.marginTop = marginTop;
		this.marginBottom = marginBottom;
	}
	
	/**
	 * 文档操作
	 * @param pdfDocument
	 * @param pdfWriter
	 */
	public void doOptions(Document pdfDocument, PdfWriter pdfWriter){
		if (pdfDocument == null) {
			return;
		}
		Rectangle rectPageSize = new Rectangle(pageSize);// A4纸张 PageSize.A4.rotate() 横向
		pdfDocument.setPageSize(rectPageSize);
		pdfDocument.setMargins(marginLeft, marginRight, marginTop, marginBottom);
	}
}
